package com.sl.au.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.sl.au.entity.BusinesssellerBaseInfo;

public interface BusinesssellerBaseInfoRepository extends JpaRepository<BusinesssellerBaseInfo, String> {
	@Query("select a from BusinesssellerBaseInfo a where a.managementPerson.id=?1")
	BusinesssellerBaseInfo getInfoByUserId(String id);
	
	@Query("select a from BusinesssellerBaseInfo a where a.id=?1")
	BusinesssellerBaseInfo getInfoById(String id);
	
	@Query("select a from BusinesssellerBaseInfo a where a.shopName like %?1% or a.managementPerson.name like %?1% or a.shopAdress like %?1%")
	Page<BusinesssellerBaseInfo> getByKey(String key,Pageable pageable);
	
	@Query("select a from BusinesssellerBaseInfo a where a.bussinessLevel.id=?1")
	Page<BusinesssellerBaseInfo> getByLevel(String level,Pageable pageable);
	
	@Query("select a from BusinesssellerBaseInfo a where (a.shopName like %?1% or a.managementPerson.name like %?1% or a.shopAdress like %?1%) and a.bussinessLevel.id =?2")
	Page<BusinesssellerBaseInfo> getByKeyAndLevel(String key,String level,Pageable pageable);
	
	@Query("select a from BusinesssellerBaseInfo a where (a.shopName like %?1% or a.managementPerson.name like %?1% or a.shopAdress like %?1%) and a.bussinessLevel is null")
	Page<BusinesssellerBaseInfo> getNoLevelByKey(String key,Pageable pageable);
	
	@Query("select a from BusinesssellerBaseInfo a where a.bussinessLevel is null")
	Page<BusinesssellerBaseInfo> findNoLevelAll(Pageable pageable);
	
	@Query("select a from BusinesssellerBaseInfo a where a.shopName=?1")
	BusinesssellerBaseInfo getInfoByName(String name);
	
	@Modifying
	@Query("update BusinesssellerBaseInfo a set a.bussinessLevel = null where a.bussinessLevel.id =?1")
	int setBusinesssellerBaseInfo(String id);
}
